<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="财务月份">
              <a-input v-model="queryParam.financialMonth" disabled />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="户号">
            <!-- <j-dict-select-tag v-model="queryParam.cusId" placeholder="请选择户号" dictCode="mws_t_arc_customers,code,id"/> -->
            <a-input placeholder="请输入户号" class="query-group-cust" v-model="queryParam.accCode" style="width:100%"></a-input> 
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="户名">
             <a-input v-model="queryParam.accName" placeholder="请输入户名"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否代收">
            <j-dict-select-tag v-model="queryParam.isProxy" placeholder="请选择是否代收" dictCode="yn"/>
              </a-form-item>
            </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="支付方式">
              <j-dict-select-tag v-model="queryParam.feePayWay" placeholder="请选择支付方式" dictCode="fee_pay_way"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="支付状态">
              <j-dict-select-tag v-model="queryParam.status" placeholder="请选择支付状态" dictCode="fee_pay_status"/>
            </a-form-item>
          </a-col>         
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="收费员">
             <a-input v-model="queryParam.createBy" placeholder="请输入收费员登录名"/>
            </a-form-item>
          </a-col>
        
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">       
       <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <!-- <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <!-- <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="缴费明细" key="chgSubPayments" forceRender>
              <chg-sub-payments-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template> -->
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="ellipsisText" slot-scope="text">
          <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>


        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleCancelPay(record)">取消预缴充值</a>
           <!--<a-divider type="vertical"/>        
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down"/></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->


    <chg-payments-modal ref="modalForm" @ok="modalFormOk"/>
    <chg-hx-arrears-modal ref="modalHxForm" @modalHxFormOk="modalHxFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction,postAction} from '@/api/manage'
  import ChgPaymentsModal from './modules/ChgPaymentsModal'
  import ChgSubPaymentsSubTable from './subTables/ChgSubPaymentsSubTable'
  import ChgHxArrearsModal from './modules/hxArrears/ChgHxArrearsModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'ChgCancelPayments',
    mixins: [JeecgListMixin],
    components: {
      ChgPaymentsModal,
      ChgSubPaymentsSubTable,
      ChgHxArrearsModal,
      JDate,
      JDictSelectTag,
    },
    data() {
      return {
        description: '取消预缴充值-缴费记录列表管理页面',
        disableMixinCreated:true,
        username:'',
        transactionId:'',
        wxtInfo:{
          transaction_id:'',
          success_time:'',
          amount:{
            total:''
          },
          out_trade_no:'',
          payer:{openid:''}
        },
        textMaxLength:5,
        row:{},
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '户号',
            align: 'center',
            dataIndex: 'accCode'
          },
          {
            title: '户名',
            align: 'center',
            dataIndex: 'accName',
            scopedSlots: {customRender: "ellipsisText"}
          },
          {
            title: '财务月份',
            align: 'center',
            dataIndex: 'financialMonth',
          },
          {
            title: '支付方式',
            align: 'center',
            dataIndex: 'feePayWay_dictText'
          },
          {
            title: '缴费金额',
            align: 'center',
            dataIndex: 'payFee',
          },
          {
            title: '上次余额',
            align: 'center',
            dataIndex: 'preMoney',
          },
          {
            title: '本次余额',
            align: 'center',
            dataIndex: 'postMoney',
          },
          // {
          //   title: '是否代收',
          //   align: 'center',
          //   dataIndex: 'isProxy_dictText'
          // },
          // {
          //   title: '商户订单号',
          //   align: 'center',
          //   dataIndex: 'id',
          // },
          // {
          //   title: '微信支付订单号',
          //   align: 'center',
          //   dataIndex: 'transactionId',
          //   scopedSlots: {customRender: "ellipsisText"}
          // },
          {
            title: '时间',
            align: 'center',
            dataIndex: 'createTime',
          },
          // {
          //   title: '代收的垃圾费',
          //   align: 'center',
          //   dataIndex: 'ljFee',
          // },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status_dictText'
          },
          {
            title: '收费员',
            align: 'center',
            dataIndex: 'createBy'
          },           
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width:80,
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/chg/chgPayments/cancelList', 
          periodPath:'/arc/basePeriod/getPeriod',
          cancelUrl: '/chg/chgPayments/cancelPay',         
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.username = this.userInfo.username;
      this.getCurrentData();
    },
    computed: {     
      userInfo() {
        return this.$store.getters.userInfo
      }  
    },
    methods: {
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },       
     
      handleCancelPay(row){        
        this.loading = true;
        postAction(this.url.cancelUrl, row).then((res) => {
          if (res.success) {
            this.$message.success("取消充值成功");
            this.resetQuery();
          }else{
            this.$message.warning(res.message);
            this.resetQuery();
          }
        }).finally(() => {
          this.loading = false
        }) 
      },
      modalHxFormOk() {     
        let selKeys= this.$refs.modalHxForm.getSelectKeys();      
        if(this.row){
          let selRow=this.row;
          selRow.arrearsIds=selKeys.toString();
          this.handleHx(selRow);
        }
      },
      getCurrentData(){
        this.loading = true       
        getAction(this.url.periodPath, {}).then((res) => {
          if (res.success) {          
            this.queryParam.financialMonth=res.result.month;
          }
        }).finally(() => {
          this.loading = false
        })           
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'cusId',text:'户号',dictCode:'mws_t_arc_customers,code,id'})
        fieldList.push({type:'string',value:'cusName',text:'户名',dictCode:''})
        fieldList.push({type:'string',value:'financialMonth',text:'财务月份',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'storedPaymentMoney',text:'预存缴费金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'money',text:'金额',dictCode:''})
        fieldList.push({type:'int',value:'isProxy',text:'是否代收',dictCode:'yn'})
        fieldList.push({type:'string',value:'batchNo',text:'缴费批号',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'ljFee',text:'代收的垃圾费',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态',dictCode:''})
        fieldList.push({type:'string',value:'feeTargetType',text:'缴费类型',dictCode:'fee_target_type'})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'datetime',value:'createTime',text:'操作时间'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>